* This file produces all tables in the main text and the appendix -- except for Tables 4, A-5, and A-6 
* Run R file "tables.R" to produce Tables 4, A-5, and A-6 

clear all
use "REPOSITORY/data/clean_survey.dta", clear

** Table 1 
regress treated education_4_5_6_7 age income_pre_IS_3_4 identity_2 vote sharia_1 prayer_4_5 gov_grievance_sunni IS_any_harm IS_zakat, cluster(Neighborhood)

** Table 2 
gen east = 1 if treated == 0
replace east = 0 if treated == 1
estpost summ cts_legitimacy police_legitimacy army_legitimacy military_legitimacy  if east== 1
estpost summ cts_legitimacy police_legitimacy army_legitimacy military_legitimacy  if east== 0
estpost ttest cts_legitimacy police_legitimacy army_legitimacy military_legitimacy, by(east)

* set macro for covariates
global demographic "gender age i.income_pre_IS i.identity i.education"
global individual "vote gov_grievance_police gov_grievance_arrested gov_grievance_sunni gov_grievance_protest IS_any_harm IS_electric IS_water IS_zakat"
global neighborhood "pop_density road_density res_density"

** Table 3 

* Column 1 
regress military_legitimacy treated, cluster(Neighborhood)
summarize military_legitimacy if e(sample)
* Column 2 
regress military_legitimacy treated $demographic, cluster(Neighborhood)
psacalc delta treated, rmax(0.0941)
summarize military_legitimacy if e(sample)
* Column 3 
eststo: regress military_legitimacy treated $demographic $individual, cluster(Neighborhood)
psacalc delta treated, rmax(0.1118)
summarize military_legitimacy if e(sample)
* Column 4
eststo: regress military_legitimacy treated $demographic $individual $neighborhood, cluster(Neighborhood)
psacalc delta treated, rmax(0.1145)
summarize military_legitimacy if e(sample)


** Table A-4 
estpost summ  education_1 education_2 education_3 education_4 education_5 education_6 education_7  age income_pre_IS_1 income_pre_IS_2 income_pre_IS_3 income_pre_IS_4 identity_1 identity_2 vote sharia_1  sharia_3 prayer IS_any_harm IS_electric IS_water IS_zakat gov_grievance_police gov_grievance_arrested gov_grievance_sunni gov_grievance_protest pop_density road_density res_density if  east== 1
estpost summ education_1 education_2 education_3 education_4 education_5 education_6 education_7  age income_pre_IS_1 income_pre_IS_2 income_pre_IS_3 income_pre_IS_4 identity_1 identity_2 vote sharia_1 sharia_3 prayer IS_any_harm IS_electric IS_water IS_zakat gov_grievance_police gov_grievance_arrested gov_grievance_sunni gov_grievance_protest pop_density road_density res_density if east== 0
estpost ttest education_1 education_2 education_3 education_4 education_5 education_6 education_7  age income_pre_IS_1 income_pre_IS_2 income_pre_IS_3 income_pre_IS_4 identity_1 identity_2 vote sharia_1 sharia_3 prayer IS_any_harm IS_electric IS_water IS_zakat gov_grievance_police gov_grievance_arrested gov_grievance_sunni gov_grievance_protest pop_density road_density res_density,by(east)

** Table A-7 
regress house_damage treated $demographic $individual $neighborhood, cluster(Neighborhood)
regress death_or_injury treated $demographic $individual $neighborhood, cluster(Neighborhood)
regress damage_in_10m_binary treated $demographic $individual $neighborhood, cluster(Neighborhood)
regress looting treated $demographic $individual $neighborhood, cluster(Neighborhood)


** Table A-8 
use "REPOSITORY/data/processed_data/health_survey.dta", clear

gen east = 1 if side == "East/left"
replace east = 0 if side == "West/right"
summ death death_airstrike death_explosions death_gunshot death_carbomb death_other_conflict  if east== 1
summ death death_airstrike death_explosions death_gunshot death_carbomb death_other_conflict  if east== 0
ttest death death_airstrike death_explosions death_gunshot death_carbomb death_other_conflict, by(east)

** Table A-9 
use "REPOSITORY/data/clean_survey.dta", clear

* Column 1 
regress military_legitimacy treated house_damage $demographic $individual $neighborhood, cluster(Neighborhood)
psacalc delta treated, rmax(0.1158)
summarize military_legitimacy if e(sample)
* Column 2 
eststo: regress military_legitimacy  treated death_or_injury $demographic $individual $neighborhood, cluster(Neighborhood)
psacalc delta treated, rmax(0.1147)
summarize military_legitimacy if e(sample)
* Column 3 
eststo: regress military_legitimacy treated damage_in_10m  $demographic $individual $neighborhood, cluster(Neighborhood)
psacalc delta treated, rmax(0.1207)
summarize military_legitimacy if e(sample)
* Column 4
eststo: regress military_legitimacy treated house_damage death_or_injury damage_in_10m $demographic $individual $neighborhood, cluster(Neighborhood)
psacalc delta treated, rmax(0.1227)
summarize military_legitimacy if e(sample)


** Table A-10 
* Column 1 
regress military_legitimacy treated##house_damage $demographic $individual $neighborhood, cluster(Neighborhood)
summarize military_legitimacy if e(sample)
margins, dydx(treated) at(house_damage=0)
margins, dydx(treated) at(house_damage=1)
margins, dydx(house_damage) at(treated=0)
margins, dydx(house_damage) at(treated=1)
* Column 2
regress military_legitimacy treated##death_or_injury $demographic $individual $neighborhood, cluster(Neighborhood)
summarize military_legitimacy if e(sample)
margins, dydx(treated) at(death_or_injury=0)
margins, dydx(treated) at(death_or_injury=1)
margins, dydx(death_or_injury) at(treated=0)
margins, dydx(death_or_injury) at(treated=1)

* Column 3
regress military_legitimacy treated##damage_in_10m_binary $demographic $individual $neighborhood, cluster(Neighborhood)
summarize military_legitimacy if e(sample)
margins, dydx(treated) at(damage_in_10m_binary=0)
margins, dydx(treated) at(damage_in_10m_binary=1)
margins, dydx(damage_in_10m_binary) at(treated=0)
margins, dydx(damage_in_10m_binary) at(treated=1)
	

** Table A-11
* Column 1 
regress military_legitimacy  looting, cluster(Neighborhood)
summarize military_legitimacy if e(sample)
* Column 2
regress military_legitimacy  looting  $demographic, cluster(Neighborhood)
summarize military_legitimacy if e(sample)
* Column 3
regress military_legitimacy  looting  $demographic $individual, cluster(Neighborhood)
summarize military_legitimacy if e(sample)
* Column 4
regress military_legitimacy  looting  $demographic $individual $neighborhood, cluster(Neighborhood)
summarize military_legitimacy if e(sample)


** Table A-12
* Column 1 
regress military_legitimacy  damage_in_10m, cluster(Neighborhood)
summarize military_legitimacy if e(sample)
* Column 2
regress military_legitimacy  damage_in_10m  $demographic, cluster(Neighborhood)
summarize military_legitimacy if e(sample)
* Column 3
regress military_legitimacy  damage_in_10m  $demographic $individual, cluster(Neighborhood)
summarize military_legitimacy if e(sample)
* Column 4
regress military_legitimacy  damage_in_10m  $demographic $individual $neighborhood, cluster(Neighborhood)
summarize military_legitimacy if e(sample)

** Table A-13 
* Column 1 
regress us_legitimacy treated $demographic $individual $neighborhood, cluster(Neighborhood)
psacalc delta treated, rmax(0.0913)
summarize us_legitimacy if e(sample)
* Column 2
regress cts_legitimacy treated $demographic $individual $neighborhood, cluster(Neighborhood)
psacalc delta treated, rmax(0.0933)
summarize cts_legitimacy if e(sample)
* Column 3
regress army_legitimacy treated $demographic $individual $neighborhood, cluster(Neighborhood)
psacalc delta treated, rmax(0.1109)
summarize army_legitimacy if e(sample)
* Column 4 
regress police_legitimacy treated $demographic $individual $neighborhood, cluster(Neighborhood)
psacalc delta treated, rmax( 0.1144)
summarize police_legitimacy if e(sample)
* Column 5
regress pmf_legitimacy treated $demographic $individual $neighborhood, cluster(Neighborhood)
psacalc delta treated, rmax(0.1054)
summarize pmf_legitimacy if e(sample)








